package main

import (
	"context"
	"fmt"
	"google.golang.org/grpc"
	"mxshop/user_srv/proto/proto_go"
)

var UserClient proto_go.UserClient
var conn *grpc.ClientConn

func init() {
	var err error
	conn, err = grpc.Dial(":5051", grpc.WithInsecure(), grpc.WithBlock())
	if err != nil {
		panic(err)
	}
	UserClient = proto_go.NewUserClient(conn)

}

// GetUserList 获取用户信息列表
func GetUserList() {
	pageInfo := &proto_go.PageInfo{Pn: 1, PSize: 10}
	userInfoList, err := UserClient.GetUserList(context.Background(), pageInfo)
	if err != nil {
		return
	}
	for _, user := range userInfoList.Data {
		fmt.Println(user.Id, user.NickName, user.Mobile, user.Password)
		var passWordInfo proto_go.PassWordInfo
		passWordInfo.Password = "123456"
		passWordInfo.EncryptedPassword = user.Password
		checkRes, err2 := UserClient.CheckPassWord(context.Background(), &passWordInfo)
		if err2 != nil {
			panic(err2)
		}
		fmt.Println(2333, checkRes)
	}
}
func CreateUser() {
	var createUserInfo proto_go.CreateUserInfo
	createUserInfo.NickName = "gaga"
	createUserInfo.Password = "123456789"
	createUserInfo.Mobile = "13592375476"
	userInfo, err := UserClient.CreateUser(context.Background(), &createUserInfo)
	if err != nil {
		panic(err)
	}
	fmt.Println(444455555, userInfo)

}
func main() {
	CreateUser()
	conn.Close()
}
